<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/11/8 0008
 * Time: 下午 8:20
 */

namespace app\controller;


use think\facade\Filesystem;
use think\facade\Validate;

class Upload
{
    function index(){


        //print_r($_FILES);

//        if(is_uploaded_file($_FILES['file']['tmp_name'])){
//
//            $file = $_FILES['file']['name'];
//            if(move_uploaded_file($_FILES['file']['tmp_name'],"./".$file)){
//                echo "上传成功";
//            }
//        }

        $file = request()->file("file");
        //dump($file);

        $validate = Validate::rule([
            "file"=>"file|fileExt:jpg,png,gif"
        ]);

        $result = $validate->check([
            "file"=>$file
        ]);
        if($result){
            $info = Filesystem::putFile("topic",$file);
            dd($info);
        }else{

            dd($validate->getError());
        }


    }

    function more(){

        $files = request()->file("file");
        $infos = [];
        foreach ($files as $file){

            $infos[] = Filesystem::putFile("topic",$file);

        }

        dd($infos);

    }
}